<?php

namespace app\admin\model\order;

use think\Model;

class Main extends Model {

    // 表名
    protected $name = 'order_main';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;
    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    // 追加属性
    protected $append = [
        'status_text'
    ];

    public function getStatusList() {
        return [ '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5')];
    }

    public function getStatusTextAttr($value, $data) {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getFlagAttr($value) {
        $flasList=array(0=>'占位',1=>'未标记',2=>'已标记');
        return $flasList[$value];
    }
    
    public function admin() {
        return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function attribute() {
        return $this->belongsTo('Attribute', 'attribute_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    
    public function trademark() {
        return $this->belongsTo('Trademark', 'trademark_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function attache() {
        return $this->belongsTo('app\admin\model\Admin', 'attache_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function province() {
        return $this->belongsTo('app\admin\model\Area', 'province_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function city() {
        return $this->belongsTo('app\admin\model\Area', 'city_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function country() {
        return $this->belongsTo('app\admin\model\Area', 'country_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
